package com.zxc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.dao.SysUserMapper;
import com.zxc.entity.SysUser;
import com.zxc.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public Map login(String username) {
        Map map = sysUserMapper.selectSysUser(username);
        return map;
    }

    @Override
    public List<SysUser> selectSysUserById(Integer userId) {
        List<SysUser> sysUserList = new ArrayList();
        if (userId == 0){
            sysUserList = sysUserMapper.selectAllSysUser();
            //我们这个方法不需要返回系统管理员的
            return sysUserList;
        }
        SysUser sysUser = sysUserMapper.selectById(userId);
        sysUserList.add(sysUser);
        return sysUserList;
    }

    @Override
    public List<SysUser> selectSysUserBySysUserName(String commonCreater) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name",commonCreater);
        List<SysUser> sysUserList = sysUserMapper.selectList(queryWrapper);
        return sysUserList;
    }

    @Override
    public String selectSysUserBySysUserId(String svrCreateBy) {
        SysUser sysUser = sysUserMapper.selectById(svrCreateBy);
        return sysUser.getUserName();
    }

    @Override
    public List<Map> loadMenu(Integer userId) {
        List<Map> mapList = sysUserMapper.loadMenu(userId);
        return mapList;
    }

    @Override
    public List<Map> loadPermission(int userId) {
        List<Map> mapList = sysUserMapper.loadPermission(userId);
        return mapList;
    }

    @Override
    public String getSysUserRole(String sysUserName) {
        String sysUserRole = sysUserMapper.selectSysUserRole(sysUserName);
        return sysUserRole;
    }
}
